1. Field of the Disclosure
The present disclosure is generally directed to a stack and, more particularly, techniques for maintaining a stack pointer for a stack.
2. Description of the Related Art
As is well known, a stack is an area of memory that is utilized to store information. Typically, computer systems have employed a stack to hold information in order to switch context to a called function and restore a calling function when the called function completed. In general, such computer systems follow a run-time protocol between calling and called functions to save arguments and return values on the stack. Stacks may be used to support nested or recursive function calls and, in this case, a stack may be used implicitly by a compiler to support various statements, e.g., call and return statements. Some programming languages use a stack to store data that is local to a procedure. In this case, space for local data items is allocated in the stack when the procedure is entered and is deallocated when the procedure is exited. A stack pointer, e.g., a stack pointer register, holds an address that points to the most recently referenced location on the stack. The two instructions that are generally applicable to all stacks are a push and a pop (or pull). A push is used to place information at a location pointed to by the stack pointer after the address in the stack pointer is adjusted by the size of the information. A pop is used to remove information at the current location pointed to by the stack pointer. The stack pointer is then adjusted by the size of the information removed.
In general, each stack has a fixed location in memory at which it begins. As data items are added to the stack, the stack pointer is displaced to indicate the current extent of the stack, which expands away from the origin (e.g., up or down, depending on the specific implementation). For example, a stack might start at a memory location of one-thousand, and expand towards lower addresses, in which case new data items are stored at locations ranging below one thousand, and the stack pointer is decremented each time a new data item is added. In this case, when a data item is removed from the stack, the stack pointer is incremented. Stack pointers may point to the origin of a stack or to a limited range of addresses either above or below the origin (depending on the direction in which the stack grows). In general, a stack pointer should not cross an origin or an end-point of the stack. For example, if the origin of the stack is at address one-thousand and the stack grows downwards (towards addresses nine-hundred ninety-nine, etc.), the stack pointer should not be incremented above one-thousand, as doing so may corrupt data associated with another application.
Traditionally, modification of a stack pointer has been achieved by providing a side-effect operation (i.e., an operation that incremented or decremented a stack pointer register) for each stack related operation. The side-effect operation added/subtracted an immediate value (based on the instruction set architecture (ISA)) to/from a stack pointer value stored in a stack pointer register. Other processor architectures have employed dedicated stack engine hardware that added/subtracted a value of a delta stack pointer to/from a value of an historic stack pointer to provide a current stack pointer value for a single ISA, e.g., an x86 ISA. The stack engine hardware then patched the delta stack pointer value into an address syllable of each stack referencing operation to allow an address generation unit (AGU) to calculate a memory location for the current stack pointer value. Using this approach, dependencies on the stack pointer register were avoided, as the value held by the stack pointer register was not normally modified during a sequence of stack operations. In this approach, updates of the delta stack pointer value were performed by a dedicated adder/subtractor. According to this approach, recovery information (that included the delta stack pointer value and code related to the stack pointer register) was saved in a table for each instruction in the event that a pipeline flush operation was required. In this architecture, when a value of the stack pointer register was required in an address syllable for a load or store instruction, a decoder automatically inserted an operation (i.e., a synchronization operation) that updated the value in the stack pointer register (i.e., added/subtracted the delta stack pointer value to/from the value in the stack pointer register). The delta stack pointer was then cleared.
What is needed is a technique for maintaining a stack pointer that improves upon known approaches.
The use of the same reference symbols in different drawings indicates similar or identical items.